package Excepciones;

import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

public class ExceptionHandler {
	
	public static void DatabaseExceptionScan(SOAPMessage message) throws SOAPException, DatabaseException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("DatabaseException")) throw new DatabaseException();
		}
	}
	
	public static void CheckExceptionScan(SOAPMessage message) throws SOAPException, CheckException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("CheckException")) throw new CheckException();
		}
	}
	
	public static void QueryExceptionScan(SOAPMessage message) throws SOAPException, QueryException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("QueryException")) throw new QueryException();
		}
	}

	public static void UpdateExceptionScan(SOAPMessage message) throws SOAPException, UpdateException {
	
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("UpdateException")) throw new UpdateException();
		}
	}
	
	public static void InvalidLogInExceptionScan(SOAPMessage message) throws SOAPException, InvalidLogInException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InvalidLogInException")) throw new InvalidLogInException();
		}
	}
	
	public static void ExistentUserExceptionScan(SOAPMessage message) throws SOAPException, ExistentUserException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("ExistentUserException")) throw new ExistentUserException();
		}
	}
	
	public static void InexistentUserExceptionScan(SOAPMessage message) throws SOAPException, InexistentUserException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InexistentUserException")) throw new InexistentUserException();
		}
	}
	
	public static void InvalidFriendshipRequestExceptionScan(SOAPMessage message) throws SOAPException,
			InvalidFriendshipRequestException {

		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InvalidFriendshipRequestException")) throw new InvalidFriendshipRequestException();
		}
	}
	
	public static void ExistentFriendshipRequestExceptionScan(SOAPMessage message) throws SOAPException,
			ExistentFriendshipRequestException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("ExistentFriendshipRequestException")) throw new ExistentFriendshipRequestException();
		}
	}
	
	public static void InexistentFriendshipRequestExceptionScan(SOAPMessage message) throws SOAPException,
			InexistentFriendshipRequestException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InexistentFriendshipRequestException")) throw new InexistentFriendshipRequestException();
		}
	}
	
	public static void InvalidFriendshipExceptionScan(SOAPMessage message) throws SOAPException, InvalidFriendshipException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InvalidFriendshipException")) throw new InvalidFriendshipException();
		}
	}
	
	public static void ExistentFriendshipExceptionScan(SOAPMessage message) throws SOAPException, ExistentFriendshipException {
	
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("ExistentFriendshipException")) throw new ExistentFriendshipException();
		}
	}
	
	public static void InexistentFriendshipExceptionScan(SOAPMessage message) throws SOAPException, InexistentFriendshipException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InexistentFriendshipException")) throw new InexistentFriendshipException();
		}
	}
	
	public static void InexistentSubjectExceptionScan(SOAPMessage message) throws SOAPException, InexistentSubjectException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InexistentSubjectException")) throw new InexistentSubjectException();
		}
	}

	public static void InvalidInscriptionExceptionScan(SOAPMessage message) throws SOAPException, InvalidInscriptionException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InvalidInscriptionException")) throw new InvalidInscriptionException();
		}
	}
	
	public static void ExistentInscriptionExceptionScan(SOAPMessage message) throws SOAPException, ExistentInscriptionException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("ExistentInscriptionException")) throw new ExistentInscriptionException();
		}
	}
	
	public static void InexistentInscriptionExceptionScan(SOAPMessage message) throws SOAPException, InexistentInscriptionException {
		
		SOAPElement soapBodyElem = (SOAPElement)message.getSOAPBody().getChildElements().next();
		if (soapBodyElem.getLocalName() == "Fault") {
			String exception = ((SOAPElement)soapBodyElem.getChildElements().next()).getValue();
			if (exception.equals("InexistentInscriptionException")) throw new InexistentInscriptionException();
		}
	}
}
